#include "Tlist.h"
#include <iostream>

Tlist::Tlist()
{
    l=NULL;
}

Tlist::~Tlist()
{
   Tbox *p;

   while (l)
   {
       p=l;
       l=l->next;
       delete p;
   }
   l=NULL;
}

void Tlist::Addfirst(int _data)
{
    Tbox *p= new Tbox (_data);
    p->next=l;
    l=p;

}
void Tlist::Addlast(int _data)
{
    Tbox *p = new Tbox (_data);

    if (!l)
    {
       l=p;
    }
    else
    {
        Tbox* q = l;
        while (q->next)
        {
            q = q->next;
        }
        q->next = p;
    }
}


void Tlist::ride()
{
    Tbox* p=l;
    while (p)
    {
        p->show();
        p=p->next;
    }
}

int Tlist::length()
{
 int s =0;
 while (l)
 {
     s=s+1;
     l=l->next;
 }
 return s;
}
